#!/usr/bin/env perl
###########################################################################
#
#   Copyright 2010 American Public Media Group
#
#   This file is part of AIR2.
#
#   AIR2 is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   AIR2 is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with AIR2.  If not, see <http://www.gnu.org/licenses/>.
#
###########################################################################

use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../../lib/perl";
use Carp;
use Data::Dump qw( dump );
use AIR2::Config;
use AIR2::Source;
use AIR2::Project;
use AIR2::SrcResponseSet;
use AIR2::Organization;
use AIR2::Inquiry;
use AIR2::User;

## example data so search indexes will build

my $project = AIR2::Project->new(
    prj_name => 'example-project',
    prj_uuid => 'example-uuid'
);
$project->load_or_save;

my $org1 = AIR2::Organization->new(
    org_default_prj_id => $project->prj_id,
    org_name           => 'example-organization',
    org_uuid           => 'example-uuid',
)->load_or_save();

my $user = AIR2::User->new(
    user_username   => 'example@nosuchemail.org',
    user_first_name => 'First',
    user_last_name  => 'Last',
    user_uuid       => 'example-uuid',
);

$user->load_or_save();

# must do this AFTER we set default_prj_id above
$project->add_project_orgs(
    [   {   porg_org_id          => $org1->org_id,
            porg_contact_user_id => $user->user_id,
        }
    ]
);

$project->save();

my $source = AIR2::Source->new( src_username => 'insightfulperson' );

$source->add_emails(
    [ { sem_email => 'insightfulperson@nosuchemail.org' } ] );

$source->add_organizations( [$org1] );
$source->load_or_save();

my $inq = AIR2::Inquiry->new(
    inq_title => 'the color query',
    inq_uuid  => 'example-uuid',
);

$inq->add_projects( [$project] );

my $ques = AIR2::Question->new( ques_value => 'what is your favorite color' );

$inq->add_questions( [$ques] );
$inq->load_or_save();

my $srs = AIR2::SrcResponseSet->new(
    srs_src_id => $source->src_id,
    srs_inq_id => $inq->inq_id,
    srs_date   => time(),
);

my $response = AIR2::SrcResponse->new(
    sr_src_id     => $source->src_id,
    sr_ques_id    => $ques->ques_id,
    sr_orig_value => 'blue is my favorite color',
);

$srs->add_responses( [$response] );
$srs->load_or_save();
